<?php	namespace Hdphp\Libs;
class SmartyView
{
	protected static $smarty = null;
	public function __construct(){
		if(!is_null(self::$smarty)) return;
		//smarty类是全局空间
		$smarty = new \Smarty();
		//模板目录
		$path = "App/" . MODULE . "/View/" . CONTROLLER;
		$smarty->template_dir = $path;
		//编译目录
		$path = "Storge/compile/" . MODULE . "/" . CONTROLLER;
		is_dir($path) || mkdir($path,0777,true);
		$smarty->compile_dir = $path;
		//缓存目录
		$path = "Storge/cache/" . MODULE . "/" . CONTROLLER;
		is_dir($path) || mkdir($path,0777,true);
		$smarty->cache_dir = $path;
		//是否缓存
		$smarty->caching = C("SMARTY_CACHING");
		//缓存时间
		$smarty->cache_lifetime = C("SMARTY_CACHE_LIFETIME");
		//开始定界符
		$smarty->left_delimiter = C("SMARTY_LEFT_DELIMITER");
		//结束定界符
		$smarty->right_delimiter = C("SMARTY_RIGHT_DELIMITER");
		//$smarty对象赋给属性
		self::$smarty  = $smarty;
		
	}
	/**
	 * 自己定义display
	 */
	protected function display($tpl=null)
	{
		//不传参数，默认找与方法名相同的模板
		if(is_null($tpl)) $tpl = ACTION . ".php";
		self::$smarty->display($tpl);
	}
	/**
	 * 自定义的assign
	 */
	protected function assign($var,$value)
	{
		self::$smarty->assign($var,$value);
	}
}










